<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input v-model="robot_name" placeholder="请输入机器人名称" clearable size="small" prefix-icon="el-icon-search"
            style="margin-bottom: 20px" @change="getRobotName($event)" />
        </div>
        <div class="head-container" style="border:1px solid #0a328a;">
          <!--机器人列表-->
          <el-table v-loading="false" :data="robotList" @row-click="getSelectdata"
            @selection-change="handleSelectionChange" :cell-style="{ borderColor: 'rgb(1 5 43)' }"
            :header-cell-style="{ borderColor: 'rgb(1 5 43)' }">
            <el-table-column label="机器人编号" align="center" prop="robot_num"/>
            <el-table-column label="机器人名称" align="center" prop="robot_name"/>
          </el-table>
        </div>
      </el-col>
      <!-- 查询条件区域-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
          <el-form-item label="池子编号" prop="pond_num">
            <el-input v-model="queryParams.pond_num" placeholder="请输入池子编号" clearable
              @keyup.enter.native="handleQuery" size="small" />
          </el-form-item>
          <el-form-item label="标签编号" prop="label_num">
            <el-input v-model="queryParams.label_num" placeholder="请输入标签编号" clearable
                      @keyup.enter.native="handleQuery" size="small" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <!--增删改查按钮区域-->
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['nssc:backwashpoint:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
              v-hasPermi="['nssc:backwashpoint:remove']">删除</el-button>
          </el-col>
          <span style="color:#418fec">注意：相同池子与标签号最多添加三条记录</span>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <!--  数据列表区域-->
        <el-table v-loading="loading" :data="backwashList" @selection-change="handleSelectionChange"
          :cell-style="{ borderColor: 'rgb(1 5 43)' }" :header-cell-style="{ borderColor: 'rgb(1 5 43)' }">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="机器人名称" align="center" prop="robot_name" />
          <el-table-column label="池子编号" align="center" prop="pond_num">
            <template slot-scope="scope">
              <span v-if="scope.row.pond_num=='1'">R滤格</span>
              <span v-if="scope.row.pond_num=='2'">S滤格</span>
              <span v-if="scope.row.pond_num=='3'">T滤格</span>
              <span v-if="scope.row.pond_num=='4'">U滤格</span>
              <span v-if="scope.row.pond_num=='5'">V滤格</span>
              <span v-if="scope.row.pond_num=='6'">W滤格</span>
              <span v-if="scope.row.pond_num=='7'">X滤格</span>
              <span v-if="scope.row.pond_num=='8'">Y滤格</span>
            </template>
          </el-table-column>
<!--            <template slot-scope="scope">
              <span v-if="scope.row.pond_num=='1'">R滤格</span>
              <span v-if="scope.row.pond_num=='2'">S滤格</span>
              <span v-if="scope.row.pond_num=='3'">T滤格</span>
              <span v-if="scope.row.pond_num=='4'">U滤格</span>
              <span v-if="scope.row.pond_num=='5'">V滤格</span>
              <span v-if="scope.row.pond_num=='6'">W滤格</span>
              <span v-if="scope.row.pond_num=='7'">X滤格</span>
              <span v-if="scope.row.pond_num=='8'">Y滤格</span>
            </template>
          </el-table-column>-->
          <el-table-column label="标签号" align="center" prop="label_num" />
          <el-table-column label="xyz角度" align="center">
            <template slot-scope="scope">
              {{ scope.row.x_point1 }},{{ scope.row.y_point1 }},{{ scope.row.z_point1 }}
            </template>
          </el-table-column>
<!--          <el-table-column label="初始角度" align="center">-->
<!--            <template slot-scope="scope">-->
<!--              {{ scope.row.x_point2 }},{{ scope.row.y_point2 }},{{ scope.row.z_point2 }}-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="变倍" align="center" prop="zoom" />-->
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                         v-hasPermi="['nssc:backwashpoint:edit']">修改</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                         v-hasPermi="['nssc:backwashpoint:remove']">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--列表分页区域-->
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" style="background:rgb(1 5 43);" />
      </el-col>
    </el-row>
    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="95px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="机器人名" prop="robot_id">
              <el-select v-model="form.robot_id" clearable  placeholder="请选机器人">
                <el-option
                    v-for="item in robotList"
                    :key="item.id"
                    :label="item.robot_name"
                    :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="池子编号" prop="pond_num" width="140">
              <el-select v-model="form.pond_num" placeholder="选池子编号">
                <el-option
                    v-for="item in pool_nums"
                    :key="item.key"
                    :label="item.pond_name"
                    :value="item.pond_num"
                ></el-option>
              </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标签编号" prop="label_num" width="140">
              <el-select v-model="form.label_num" placeholder="选标签编号">  <!--@change="getOptionfcx"-->
                <el-option
                    v-for="item in label_nums"
                    :key="item.key"
                    :label="item.label_name"
                    :value="item.label_num"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item label="变倍设置" prop="zoom">-->
<!--              <el-input v-model="form.zoom" placeholder="请输入变倍值（1-4）" style="width: 200px" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="12">
            <el-form-item label="X坐标" prop="x_point1">
              <el-input v-model="form.x_point1" placeholder="请输入X坐标" style="width: 200px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="Y坐标" prop="y_point1">
              <el-input v-model="form.y_point1" placeholder="请输入Y坐标" style="width: 200px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="Z坐标" prop="z_point1">
              <el-input v-model="form.z_point1" placeholder="请输入Z坐标" style="width: 200px" />
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">
            <el-form-item label="X初始坐标" prop="x_point2">
              <el-input v-model="form.x_point2" placeholder="请输入初始X坐标" style="width: 200px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="Y初始坐标" prop="y_point2">
              <el-input v-model="form.y_point2" placeholder="请输入初始Y坐标" style="width: 200px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="Z初始坐标" prop="z_point2">
              <el-input v-model="form.z_point2" placeholder="请输入初始Z坐标" style="width: 200px" />
            </el-form-item>
          </el-col>-->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" id="trackmapid" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import "@/assets/styles/robt-bg.css";
import {listonPageRobotConfig} from "@/api/nssc/robotconfig/robotconfig";
import {
  addBackwashPoint,
  delBackwashPoint,
  getBackwashPoint,
  listBackwashPoint,
  updateBackwashPoint
} from "@/api/nssc/backwashpoint/backwashpoint";
import {listTrackMap} from "@/api/nssc/map/map";
import $ from "jquery";
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      robot_name: undefined,
      // 总条数
      total: 0,
      // 反冲洗表格数据
      backwashList: [],
      //机器人表格数据
      robotList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      pool_nums:[
        {pond_num:1,pond_name:'1'},{pond_num:2,pond_name:'2'},{pond_num:3,pond_name:'3'},{pond_num:4,pond_name:'4'},
        {pond_num:5,pond_name:'5'},{pond_num:6,pond_name:'6'},{pond_num:7,pond_name:'7'},{pond_num:8,pond_name:'8'}
      ],
      label_nums:[
        {label_num:1,label_name:'1'},{label_num:2,label_name:'2'},{label_num:3,label_name:'3'},{label_num:4,label_name:'4'},
        {label_num:5,label_name:'5'},{label_num:6,label_name:'6'},{label_num:7,label_name:'7'},{label_num:8,label_name:'8'}
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        robot_name: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        robot_id: [
          { required: true, message: "机器人名称不能为空", trigger: "blur" }
        ],
        pond_num:[
          { required: true, message: "池子编号不能为空", trigger: "blur" }
        ],
        label_num:[
          { required: true, message: "标签号不能为空", trigger: "blur" }
        ],
        x_point1:[
          { required: true, message: "X坐标不能为空", trigger: "blur" }
        ],
        y_point1:[
          { required: true, message: "y坐标不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();//反洗点位列表
    this.getrobotList();//机器人列表
  },
  methods: {
    //根据机器人id池子编号标签号查询是否创建
    getOptionfcx() {
      this.queryParams.robot_id = this.form.robot_id;
      this.queryParams.pond_num = this.form.pond_num;
      this.queryParams.label_num = this.form.label_num;
      listBackwashPoint(this.queryParams).then(response => {
        if (typeof (response) != "undefined" && response != null && response.rows.length > 0) {
          $("#trackmapid").css("display", "none");
          this.$modal.confirm1('当前反冲洗巡检点已配置！');
          this.queryParams.robot_id = null;
        } else {
          $("#trackmapid").css("display", "");
          this.queryParams.robot_id = null;
        }
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增反洗点位";
      this.getrobotList();//反冲洗列表
    },
    /** 根据输入框机器人名称，查询机器人列表 */
    getRobotName(robot_name) {
      this.queryParams.robot_name = robot_name;
      this.getrobotList();
    },
    /** 查询机器人列表 */
    getrobotList() {
      this.loading = false;
      listonPageRobotConfig(this.queryParams).then(response => {
        this.robotList = response.rows;
      });
    },
    //获取当前选中机器人数据
    getSelectdata(row) {
      this.queryParams.robot_id = row.id;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除选中的数据项？').then(function () {
        return delBackwashPoint(ids);
      }).then(() => {
        this.queryParams.robot_id = null;
        this.queryParams.pond_num = null;
        this.queryParams.label_num = null;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 查询反洗点位列表 */
    getList() {
      this.loading = true;
      listBackwashPoint(this.queryParams).then(response => {
        this.backwashList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      $("#trackmapid").css("display", "");
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        robot_id : null,
        pond_num : null,
        label_num : null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.robot_id = null;
      this.queryParams.pond_num = null;
      this.queryParams.label_num = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      getBackwashPoint(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "反冲洗点位设置";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateBackwashPoint(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.queryParams.robot_id = null;
              this.queryParams.pond_num = null;
              this.queryParams.label_num = null;
              this.getList();
            });
          } else {
            addBackwashPoint(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.queryParams.robot_id = null;
              this.queryParams.pond_num = null;
              this.queryParams.label_num = null;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-input--medium .el-input__inner {
  font-size: 12px !important;
}
</style>
